﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace NeuroForecast
{
    /// <summary>
    /// Interaction logic for AddingCriterion.xaml
    /// </summary>
    public partial class AddingCriterion : Window
    {
        public enum EAddingCriterionMode { ByHands, FromFile }

        #region EventDefinition
        public delegate void AddingCriterionEventHandler(object sender, AddingCriterionEventArgs e);

        public event AddingCriterionEventHandler AddingCriterionEvent;

        public class AddingCriterionEventArgs : EventArgs
        {
            public String Name { set; get; }
            public EAddingCriterionMode AddingCriterionMode { set; get; }
            public String Path { set; get; }

            public AddingCriterionEventArgs(String name, EAddingCriterionMode addingCriterionMode, String path)
            {
                Name = name;
                AddingCriterionMode = addingCriterionMode;
                Path = path;
            }
        }

        public virtual void RaiseAddingCriterionEvent()
        {
            if (AddingCriterionEvent != null)
            {
                AddingCriterionEvent(this, new AddingCriterionEventArgs(CriterionName, AddingCriterionMode, PathToFile));
            }
        }
        #endregion

        public String CriterionName
        {
            set { tb_CriterionName.Text = value; }
            get { return tb_CriterionName.Text; }
        }
        public String PathToFile
        {
            set { tb_FilePath.Text = value; }
            get { return tb_FilePath.Text; }
        }
        public EAddingCriterionMode AddingCriterionMode
        {
            set
            {
                switch (value)
                {
                    case EAddingCriterionMode.ByHands:
                        {
                            radioButton1.IsChecked = true;
                            radioButton2.IsChecked = false;
                            break;
                        }
                    case EAddingCriterionMode.FromFile:
                        {
                            radioButton1.IsChecked = true;
                            radioButton2.IsChecked = false;
                            break;
                        }
                }
            }
            get { return (radioButton1.IsChecked == true) ? EAddingCriterionMode.ByHands : EAddingCriterionMode.FromFile; }
        }

        public AddingCriterion()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            //dlg.FileName = "Document"; // Default file name
            dlg.DefaultExt = ".csv"; // Default file extension
            dlg.Filter = "Text documents (.csv)|*.csv"; // Filter files by extension

            // Show open file dialog box
            Nullable<bool> result = dlg.ShowDialog();

            // Process open file dialog box results
            if (result == true)
            {
                // Open document
                PathToFile = dlg.FileName;
            }
        }

        private void but_Cancel_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void but_Ok_Click(object sender, RoutedEventArgs e)
        {
            Close();
            RaiseAddingCriterionEvent();
        }

        private void radioButton1_Checked(object sender, RoutedEventArgs e)
        {
            radioButton2.IsChecked = !radioButton1.IsChecked;
        }

        private void radioButton2_Checked(object sender, RoutedEventArgs e)
        {
            radioButton1.IsChecked = !radioButton2.IsChecked;
        }
    }


}
